package com.github.zj.dreamly.design.pattern.pattern.creational.singleton;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 苍海之南
 */
public class ContainerSingleton {

	private ContainerSingleton() {

	}

	private static Map<String, Object> singletonMap = new HashMap<String, Object>();

	public static void putInstance(String key, Object instance) {
		if (StringUtils.isNotBlank(key) && instance != null) {
			if (!singletonMap.containsKey(key)) {
				singletonMap.put(key, instance);
			}
		}
	}

	public static Object getInstance(String key) {
		return singletonMap.get(key);
	}

}
